package com.ptu.mapper;

import com.ptu.dto.SeckillProductDTO;
import com.ptu.entity.SeckillProduct;
import com.ptu.vo.SeckillProductVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import java.util.List;

@Mapper
public interface SeckillProductMapper {
    @Insert("insert into seckill_product(name,description,image,original_price,price,stock,status,created_time,updated_time) values(#{name},#{description},#{image},#{originalPrice},#{price},#{stock},#{status},NOW(),NOW())")
    void addSeckillProduct(SeckillProduct seckillProduct);

    @Select("select * from seckill_product")
    List<SeckillProduct> list();

    @Select("select * from seckill_product")
    List<SeckillProductVO> userGetList();

    @Select("delete from seckill_product where id=#{id}")
    void deleteById(Long id);

    @Update("update seckill_product set name=#{name},description=#{description},image=#{image},original_price=#{originalPrice},price=#{price},stock=#{stock},updated_time=NOW() where id=#{id}")
    void update(SeckillProductDTO seckillProductDTO);


    @Select("select * from seckill_product where id= #{id}")
    SeckillProduct getDetailById(Long id);

    @Update("update seckill_product set status=#{status},updated_time=NOW() where id=#{id}")
    void updateStatusById(Long id ,Integer status);

    @Select("select * from seckill_product where name= #{name}")
    SeckillProduct getDetailByName(String name);

    @Update("update seckill_product set stock=stock-1,updated_time=NOW() where id= #{productId}")
    boolean deductStock(Long productId);

    @Update("update seckill_product set stock=stock+1,updated_time=NOW() where id= #{id}")
    void resumeStock(Long id);
}
